
package ru.ifmo.mlarinsky.classificator.parsing;

/**
 *
 * @author Михаил
 */
class ParseException extends RuntimeException {

    public ParseException(String dataString, String reason, String... patterns) {
        super(buildMessage(dataString, reason, patterns));
    }

    private static String buildMessage(String dataString, String reason,
            String... patterns)
    {
        StringBuilder sb = new StringBuilder();
        for (String pattern : patterns) {
            sb.append(pattern).append(", ");
        }
        int lastIndexOf = sb.lastIndexOf(", ");
        if (lastIndexOf >= 0) {
            sb.delete(lastIndexOf, lastIndexOf + 2);
        }
        if (sb.length() == 0) {
            sb.append("null");
        }

        return "Can not parse data string '" + dataString + "'. Reason: " +
                reason + "\nPatterns: " + sb.toString();

    }
}
